<% layout('/layouts/default.html', {title: '路由器设备管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="javascript:;" onclick="bindDevice(`${rtDevice.dailishangId}`)" class="btn btn-default" title="${text('新增路由器设备')}"><i class="fa fa-plus"></i> ${text('绑定')}</a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${rtDevice}" action="${ctx}/rt/rtDevice/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<#form:hidden path="dailishangId" />
				<div class="form-group">
					<label class="control-label">${text('SN')}：</label>
					<div class="control-inline">
						<#form:input path="sn" maxlength="255" class="form-control width-120"/>
					</div>
				</div>

				<div class="form-group">
					<label class="control-label">${text('设备状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="online" blankOption="true" dictType="rt_online_code" class="form-control " />
					</div>
				</div>

				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm isQuick">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>

<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	shrinkToFit: false,
	frozenCols: true,
	columnModel: [
		{header:'${text("设备号")}', name:'sn', index:'a.sn', width:300, align:"left"},
		{header:'${text("客户手机号")}', name:'icUser.mobile', index:'a.user_id', width:150, align:"center"},
		{header:'${text("设备类型")}', name:'pipeType', index:'a.pipe_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('rt_device_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("设备状态")}', name:'online', index:'a.online', width:150, align:"center", formatter: function(val, obj, row, act){
			var status = js.getDictLabel(${@DictUtils.getDictListJson('rt_online_code')}, val, '${text("未知")}', true);
			if(status=="离线"){
				return "<span style='color: red'>"+status+"</span>";
			}
			return js.getDictLabel(${@DictUtils.getDictListJson('rt_online_code')}, val, '${text("未知")}', true);
		}},
		{header:'${text("设备架构")}', name:'model', index:'a.model', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('rt_model')}, val, '${text("未知")}', true);
		}},

		{header:'${text("设备创建时间")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
		{header:'${text("实时上行")}', name:'flow', index:'a.flow', width:150, align:"left"},
		{header:'${text("实时下行")}', name:'flowDownload', index:'a.flow_download', width:150, align:"left"},
		{header:'${text("备注")}', name:'remark', index:'a.remark', width:150, align:"left"},
		{header:'${text("测速总带宽")}', name:'uploadSpeed', index:'a.upload_speed', width:150, align:"left"},
		{header:'${text("刷新时间")}', name:'refreshTime', index:'a.upload_speed', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions',frozen:true, width:120, formatter: function(val, obj, row, act){
			var actions = [];
			actions.push('<a href="${ctx}/rt/rtDailiDevice/deleteSn?sn='+row.sn+'" class="btnList" title="${text("解绑设备")}" data-confirm="${text("确认要解绑该设备吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

</script>
<script id="bind-device" type="text/template">
	<form id="inputForm" action="${ctx}/rt/rtDailiDevice/save" method="post" enctype="multipart/form-data"
		  class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
		<div class="row">
			<div class="col-xs-12 col-xs-offset-1">
				<input type="hidden" id="dailishangId" name="dailishangId" class="form-file"/>
				<label class="control-label col-sm-2" title="">
					<span class="required hide">*</span> ${text('SN')}：<i class="fa icon-question hide"></i></label>
				<div class="col-sm-8">
					<#form:input name="sn" maxlength="100" class="form-control"/>
				</div>
			</div>
		</div>
	</form>
</script>
<script>
	function bindDevice(id){
		js.layer.open({
			type: 1,
			area: ['600px'],
			title: '${text("绑定设备")}',
			resize: false,
			scrollbar: true,
			content: js.template('bind-device'),
			success: function(layero, index){
				layero.find('#dailishangId').val(id);
			},
			btn: ['<i class="fa fa-check"></i> ${text("提交")}',
				'<i class="fa fa-remove"></i> ${text("关闭")}'],
			btn1: function(index, layero){
				var form = {
					inputForm: layero.find('#inputForm'),
				};
				// console.log(layero.find('#sn').val());
				js.ajaxSubmitForm(form.inputForm, function(data){
					if(data.result == Global.TRUE){
						js.showMessage("绑定成功");
						layero.find('#sn').val("");
						layero.find('#sn').focus();
						page();
					}else{
						js.showErrorMessage(data.message);
					}
				}, "json");
				return false;
			}
		});
	}
</script>